package com.eddie.turlingdemo;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView.FindListener;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class DataAdapter extends BaseAdapter {

	private List<ListData> list;
	private Context mContext;
	private RelativeLayout layout;
	
	public DataAdapter(List<ListData> list, Context mContext) {
		super();
		this.list = list;
		this.mContext = mContext;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = LayoutInflater.from(mContext);
		if(list.get(position).getFlag() == ListData.RECEIVE_FLAG){
			layout = (RelativeLayout) inflater.inflate(R.layout.left_item, null);
		}
		else if(list.get(position).getFlag() == ListData.SEND_FLAG){
			layout = (RelativeLayout) inflater.inflate(R.layout.right_item, null);
		}
		TextView tv = (TextView) layout.findViewById(R.id.tv);
		TextView time = (TextView) layout.findViewById(R.id.timeText);
		
		tv.setText(list.get(position).getContent());
		time.setText(list.get(position).getTime());
		return layout;
	}

}
